package org.utils.cmdline.parameters;

import org.utils.cmdline.GenericCommand;

public class TerminalParameter extends CommandParameter {

    private String exitMessage;

//accessing
    public String exitMessage() {
	return exitMessage;
    }

    public void exitMessage(String message) {
	exitMessage = message;
    }

//default message
    public String defaultMessage() {
	return "Exiting program";
    }

//testing
    public boolean isTerminal() {
	return true;
    }

//action
    protected void exit() {
	displayAndExit(zero());
    }

    protected void displayAndExit(int code) {
	display();
	System.exit(code);
    }

    protected void display() {
	display(exitMessage());
    }

    protected void display(String message) {
	out(message);
    }

    public void actUpon(GenericCommand command) {
	exit();
    }

//construction
    //protected TerminalParameter(Object key,int additionalParameterLength) {
    public TerminalParameter(int additionalParameterLength) {
		super(additionalParameterLength);
		throwExceptionWhen(
			additionalParameterLength != 0,
			new IllegalArgumentException("Terminal Parameters must not have arguments")
		);
		exitMessage(defaultMessage());
    }

    //protected TerminalParameter(Object key,int additionalParameterLength,
    public TerminalParameter(int additionalParameterLength,String message) {
		super(additionalParameterLength);
		exitMessage(message);
    }
}

